<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>申请订舱单 | </title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="font/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <!--<link href="css/nprogress.css" rel="stylesheet">-->

    <!-- Custom Theme Style -->
    <link href="css/custom.min.css" rel="stylesheet">
</head>

<body class="nav-md">
<div class="container body">
    <div class="main_container">
        <div  id="head">

        </div>


        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
            <div class="">
                <div class="page-title">
                    <div class="title_left">
                        <h3>申请订舱单</h3>
                    </div>


                </div>
                <div class="clearfix"></div>

                <div class="row">
                    <div class="col-md-12 col-sm-12 col-xs-12">
                        <div class="x_panel">

                            <div class="x_content">

                                <form class="form-horizontal form-label-left" novalidate>


                                    <span class="section">订舱单信息</span>

                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="orderNumber">订单号 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="orderNumber" style="width: 300px" class="form-control col-md-7 col-xs-12"   readonly type="text">
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="bookingno">订舱申请号 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input id="bookingno" style="width: 300px" class="form-control col-md-7 col-xs-12"   placeholder="请输入订舱申请号" type="text">
                                            <span id="bookingnoError" style="margin-left: 20px;line-height: 34px;color: red;display: none"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" >合作公司 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                      		<select id="companyName" style="height: 30px;width: 300px">
                                      			<option value="0">请选择</option>
                                      		</select>
                                            <span id="companyNameError" style="margin-left: 20px;line-height: 34px;color: red;display: none"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="bookingcarrier">承运人 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="width: 300px" type="text" id="bookingcarrier"   placeholder="请输入正确的承运人名字" class="form-control col-md-7 col-xs-12">
                                            <span id="bookingcarrierError" style="margin-left: 20px;line-height: 34px;color: red;display: none"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="receiver">收货人 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="width: 300px" type="text" id="receiver"   placeholder="请输入正确的收货人名字" class="form-control col-md-7 col-xs-12">
                                            <span id="receiverError" style="margin-left: 20px;line-height: 34px;color: red;display: none;"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="notifyparty">通知人 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="width: 300px" id="notifyparty" type="text" name="occupation" placeholder="请输入正确的通知人"data-validate-length-range="5,20" class="optional form-control col-md-7 col-xs-12">
                                            <span id="notifypartyError" style="margin-left: 20px;line-height: 34px;color: red;display: none;"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="loadingport">装货港 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="width: 300px" type="text" id="loadingport"   placeholder="请填写装货港名字" class="form-control col-md-7 col-xs-12">
                                            <span id="loadingportError" style="margin-left: 20px;line-height: 34px;color: red;display: none"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="dischargeport">卸货港 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="width: 300px" type="text" id="dischargeport"   placeholder="请填写卸货港名字" class="form-control col-md-7 col-xs-12">
                                            <span id="dischargeportError" style="margin-left: 20px;line-height: 34px;color: red;display: none;"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label for="receivingPlace" class="control-label col-md-3">收货人地址</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="width: 300px" id="receivingPlace" type="text"  placeholder="请输入正确的收货人地址"data-validate-length="6,8" class="form-control col-md-7 col-xs-12" >
                                            <span id="receivingPlaceError" style="margin-left: 20px;line-height: 34px;color: red;display: none"></span>
                                        </div>
                                    </div>

                                    
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" >是否集拼 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <select id="jipin" style="height: 34px;width: 50px">
                                                <option value="2">否</option>
                                                <option value="1">是</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="item form-group" id="SPELNO2" style="display: none">
                                        <label for="spelno" class="control-label col-md-3">集拼号</label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <input style="width: 300px" id="spelno" type="text"  placeholder="请输入正确的集拼号"data-validate-length="6,8" class="form-control col-md-7 col-xs-12" >
                                            <span id="spelnoError" style="margin-left: 20px;line-height: 34px;color: red;display: none"></span>
                                        </div>
                                    </div>
                                    <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="remarks">备注 <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <textarea style="width: 300px" id="remarks" name="textarea" class="form-control col-md-7 col-xs-12"></textarea>
                                        </div>
                                    </div>
                                    <div class="ln_solid"></div>
                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-3">
                                            <button id="send" type="button" class="btn btn-success">保存</button>
                                            <button type="button" class="btn btn-primary" onclick="window.print()">打印</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- /page content -->

        <!-- footer content -->
        <footer>
            <div class="pull-right">
                Gentelella - Bootstrap Admin Template by <a href="https://colorlib.com">Colorlib</a>
            </div>
            <div class="clearfix"></div>
        </footer>
        <!-- /footer content -->
    </div>
</div>

<!-- jQuery -->
<script src="js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<!-- FastClick -->
<script src="js/fastclick.js"></script>
<!-- NProgress -->
<script src="js/nprogress.js"></script>
<!-- validator -->

<!-- Custom Theme Scripts -->


<!-- validator -->
<script>
    var $token=window.sessionStorage.getItem('token');
    var url = window.location.href;
    var termsId = url.split("=")[1];
    $("#orderNumber").val(termsId);
    $.ajax({
        type:"post",
        xhrFields:{withCredentials:true},
        url:"http://localhost:8081/booking/showAddBooking",
        dataType:"json",
        data:{"orderNumber":termsId,"token":$token},
        success:function (data) {
            $.each(data, function (i, company) {
                $("#companyName").append("<option value='"+company.id+"'>"+company.cName+"</option>");
            })

        },
        error:function(){
            alert("异常");
        }
    });

    $("#bookingno").blur(function() {
        if ($(this).val()==0){
            $("#bookingnoError").show();
            $("#bookingnoError").html("请输入订舱申请号");
        }else {
            $("#bookingnoError").hide();
        }
    });

    $("#companyName").blur(function() {
       if ($(this).val()==0){
           $("#companyNameError").show();
           $("#companyNameError").html("请选择合作公司");
       }else {
           $("#companyNameError").hide();
       }
    });

    $("#bookingcarrier").blur(function() {
        if ($(this).val()==0){
            $("#bookingcarrierError").show();
            $("#bookingcarrierError").html("请输入承运人名字");
        }else {
            $("#bookingcarrierError").hide();
        }
    });
    $("#receiver").blur(function() {
        if ($(this).val()==0){
            $("#receiverError").show();
            $("#receiverError").html("请输入收货人名字");
        }else {
            $("#receiverError").hide();
        }
    });
    $("#notifyparty").blur(function() {
        if ($(this).val()==0){
            $("#notifypartyError").show();
            $("#notifypartyError").html("请输入通知人名字");
        }else {
            $("#notifypartyError").hide();
        }
    });
    $("#loadingport").blur(function() {
        if ($(this).val()==0){
            $("#loadingportError").show();
            $("#loadingportError").html("请输入装货港");
        }else {
            $("#loadingportError").hide();
        }
    });
    $("#dischargeport").blur(function() {
        if ($(this).val()==0){
            $("#dischargeportError").show();
            $("#dischargeportError").html("请输入卸货港");
        }else {
            $("#dischargeportError").hide();
        }
    });
    $("#receivingPlace").blur(function() {
        if ($(this).val()==0){
            $("#receivingPlaceError").show();
            $("#receivingPlaceError").html("请输入收货人地址");
        }else {
            $("#receivingPlaceError").hide();
        }
    });

    $("#jipin").blur(function() {
        if ($(this).val()==1){
            $("#SPELNO2").show();
        }else {
            $("#spelno").val("");
            $("#SPELNO2").hide();
        }
    });

    $("#spelno").blur(function() {
        var $pattern = /^\d{4,5}$/;
        if ($(this).val()=="" || !($pattern.test($(this).val()))){
            $("#spelnoError").show();
            $("#spelnoError").html("请输入正确的集拼号");
        }else {
            $("#spelnoError").hide();
        }
    });


    //提交申请订舱单
    $("#send").click(function() {
        var $bookingno  =$("#bookingno").val();
        var $companyName  =$("#companyName").val();
        var $bookingcarrier  =$("#bookingcarrier").val();
        var $receiver  =$("#receiver").val();
        var $notifyparty  =$("#notifyparty").val();
        var $loadingport  =$("#loadingport").val();
        var $dischargeport  =$("#dischargeport").val();
        var $receivingPlace  =$("#receivingPlace").val();
        var $jipin  =$("#jipin").val();
        var $spelno = $("#spelno").val();
        var $remarks  =$("#remarks").val();
        var $pattern = /^\d{4,5}$/;
        if ($bookingno==0){
            $("#bookingnoError").show();
            $("#bookingnoError").html("请输入订舱申请号");
            return;
        }else if ($companyName==0){
            $("#companyNameError").show();
            $("#companyNameError").html("请选择合作公司");
            return;
        }else if ($bookingcarrier==""){
            $("#bookingcarrierError").show();
            $("#bookingcarrierError").html("请输入承运人名字");
            return;
        }else if ($receiver==""){
            $("#receiverError").show();
            $("#receiverError").html("请输入收货人名字");
            return;
        }else if ($notifyparty==""){
            $("#notifypartyError").show();
            $("#notifypartyError").html("请输入通知人名字");
            return;
        }else if ($loadingport==""){
            $("#loadingportError").show();
            $("#loadingportError").html("请输入装货港");
            return;
        }else if ($dischargeport==""){
            $("#dischargeportError").show();
            $("#dischargeportError").html("请输入卸货港");
            return;
        }else if ($receivingPlace==""){
            $("#receivingPlaceError").show();
            $("#receivingPlaceError").html("请输入收货人地址");
            return;
        }else if ($jipin==1 && ($spelno =="" || !($pattern.test($spelno)))){
            $("#spelnoError").show();
            $("#spelnoError").html("请输入正确的集拼号");
            return;
        }else {
            $.ajax({
                type:"post",
                xhrFields:{withCredentials:true},
                url:"http://localhost:8081/booking/addBooking",
                dataType:"json",
                data:{"orderNumber":termsId,"bookingno":$bookingno,"shipinno":$companyName,"bookingcarrier":$bookingcarrier,"receiver":$receiver,
                    "notifyparty":$notifyparty,"loadingport":$loadingport,"dischargeport":$dischargeport,
                    "receivingplace":$receivingPlace, "spelno":$spelno,"remarks":$remarks,"token":$token},
                success:function (data) {
                    if(data.message=="no"){
                        alert("无法添加");
                        return;
                    }else if(data.message=="toShip"){
                        window.location.href='booking_order.html';
                    }else{
                        window.location.href='air_order.html';
                    }

                },
                error:function(){
                    alert("异常");
                }
            });
        }

    });


    // initialize the validator function
    // validator.message.date = 'not a real date';
    $('#head').load("head.html");
    // validate a field on "blur" event, a 'select' on 'change' event & a '.reuired' classed multifield on 'keyup':
    // $('form')
    //     .on('blur', 'input[required], input.optional, select.required', validator.checkField)
    //     .on('change', 'select.required', validator.checkField)
    //     .on('keypress', 'input[required][pattern]', validator.keypress);

    $('.multi.required').on('keyup blur', 'input', function() {
        validator.checkField.apply($(this).siblings().last()[0]);
    });

    $('form').submit(function(e) {
        e.preventDefault();
        var submit = true;

        // evaluate the form using generic validaing
        if (!validator.checkAll($(this))) {
            submit = false;
        }

        if (submit)
            this.submit();

        return false;
    });
</script>
<!-- /validator -->
</body>
</html>